<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id')->comment('用户Id');
            $table->string('username', 50)->unique()->default('')->comment('用户名');
            $table->string('password', 100)->default('')->comment('密码');
            $table->string('nickname', 50)->default('')->comment('昵称');
            $table->string('mobile', 30)->default('')->comment('手机号');
            $table->string('email', 100)->default('')->comment('邮箱');
            $table->string('sex', 10)->default('')->comment('性别');
            $table->string('prov', 50)->default('')->comment('省');
            $table->string('city', 50)->default('')->comment('市');
            $table->string('dist', 50)->default('')->comment('区');
			$table->string('avatar', 100)->default('')->comment('头像');
            $table->tinyInteger('status')->default(0)->comment('状态:0禁用/1启用');
            $table->string('remember_token', 100)->nullable()->comment('记住我');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
            $table->dateTime('deleted_at')->nullable()->comment('删除时间');
        });

        Schema::create('user_logs', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->default(0)->comment('用户Id');
            $table->integer('login_ip')->default(0)->comment('登录IP');
            $table->unsignedInteger('login_at')->default(0)->comment('登录时间');
            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
        });

        Schema::create('user_auth', function (Blueprint $table) {
            $table->unsignedInteger('id')->comment('用户Id');
            $table->string('card_id', 30)->default('')->comment('身份证号');
            $table->string('realname', 30)->default('')->comment('真实姓名');
            $table->string('card_pic1', 100)->default('')->comment('身份证图片1');
            $table->string('card_pic2', 100)->default('')->comment('身份证图片2');
            $table->tinyInteger('auth_status')->default(0)->comment('认证状态:0未认证/1已认证');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
            $table->primary('id');
        });

        Schema::create('user_codes', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email', 100)->default('')->comment('邮箱');
            $table->string('mobile', 30)->default('')->comment('手机号');
            $table->string('code', 100)->default('')->comment('验证码');
            $table->dateTime('expired_at')->nullable()->comment('过期时间');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
        });
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_codes');
        Schema::dropIfExists('user_auth');
        Schema::dropIfExists('user_logs');
        Schema::dropIfExists('users');
    }
}
